package adam2;

import java.io.File;

//Walking recursively searches a directory and its subdirectories for media of a particular specified type
public class Walkin {
	//static String list;
	//The directory is passed in the Server class
	public static String walkin(final File dir) {
		String list = ""; //added to prevent duplication
		
		final String pattern1 = ".avi";// REPLACE with media file extension
		final String pattern2 = ".txt";// REPLACE with media file extension

		final File listFile[] = dir.listFiles();
		if (listFile != null) {
			for (int i = 0; i < listFile.length; i++) {
				if (listFile[i].isDirectory()) {
					Walkin.walkin(listFile[i]);
				} else {

					if (listFile[i].getName().endsWith(pattern1)
							|| listFile[i].getName().endsWith(pattern2)) {

						//Walkin.list += listFile[i].getPath() + " ";
						list += listFile[i].getPath() + " ";

					}
				}
			}
		}
		//return Walkin.list;
		return list;
	}

}